package jdk5.misc;

import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Deal {
    public static void main(String args[]) {
        if(args.length != 2){ 
           System.out.println("Usage: java  " + Deal.class.getName() + 
                                                  "  numHands cardPerHand");
           System.exit(1);
        }
        int numHands = Integer.parseInt(args[0]);
        int cardsPerHand = Integer.parseInt(args[1]);
        List<Card> deck  = Card.newDeck();
        Collections.shuffle(deck);
        for (int i=0; i < numHands; i++)
            System.out.println(deal(deck, cardsPerHand));
    }

    public static ArrayList<Card> deal(List<Card> deck, int n) {
         int deckSize = deck.size();
         List<Card> handView = deck.subList(deckSize-n, deckSize);
         ArrayList<Card> hand = new ArrayList<Card>(handView);
         handView.clear();
         return hand;
     }
}

